﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace BambolettaDB
{
    public class StringItemVM: BaseVM, IEditableObject
    {
        public long ID = -1;

        private string _Text = "";
        public string Text
        {
            get { return _Text; }
            set { _Text = value; NotifyPropertyChanged("Text"); }
        }

        public string SourceTable = "";
        public string SourceColumn = "";

        public StringItemVM()
        {
        }

        public StringItemVM(long id, string text, string sourcetable, string sourceolumn)
        {
            ID = id;
            Text = text;
            SourceTable = sourcetable;
            SourceColumn = sourceolumn;
        }

        public override bool Equals(object obj)
        {
            StringItemVM other = obj as StringItemVM;
            if (other != null)
                return (ID == other.ID);

            return base.Equals(obj);
        }

        public override int GetHashCode()
        {
            return (int)ID;
        }

        public void BeginEdit()
        {
        }

        public void CancelEdit()
        {
        }

        public void EndEdit()
        {
            if (ID != -1)
                DBCommands.UpdateStringItem(this);
        }
    }
}
